package com.bj.dz.service.impl;

import com.bj.dz.entity.ElectricityChangeStation;
import com.bj.dz.mapper.ElectricityChangeStationMapper;
import com.bj.dz.service.ElectricityChangeStationService;
import com.bj.dz.util.Constants;
import com.bj.dz.util.EmptyUtils;
import com.bj.dz.util.Page;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Slf4j
@Service
public class ElectricityChangeStationServiceImpl implements ElectricityChangeStationService {

    @Resource
    private ElectricityChangeStationMapper electricityChangeStationMapper;

    public ElectricityChangeStation getElectricityChangeStationById(Integer id){
        return electricityChangeStationMapper.getElectricityChangeStationById(id);
    }

    public List<ElectricityChangeStation>	getElectricityChangeStationListByMap(Map<String,Object> param){
        return electricityChangeStationMapper.getElectricityChangeStationListByMap(param);
    }

    public Integer getElectricityChangeStationCountByMap(Map<String,Object> param){
        return electricityChangeStationMapper.getElectricityChangeStationCountByMap(param);
    }

    @Transactional
    public boolean addElectricityChangeStation(ElectricityChangeStation electricityChangeStation){
            return electricityChangeStationMapper.insertElectricityChangeStation(electricityChangeStation)>0?true:false;
    }

    @Transactional
    public boolean modifyElectricityChangeStation(ElectricityChangeStation electricityChangeStation){
        return electricityChangeStationMapper.updateElectricityChangeStation(electricityChangeStation)>0?true:false;
    }

    @Transactional
    public boolean deleteElectricityChangeStationById(Integer id){
        return electricityChangeStationMapper.deleteElectricityChangeStationById(id)>0?true:false;
    }

    public Page<ElectricityChangeStation> queryElectricityChangeStationPageByMap(Map<String,Object> param, Integer pageNo, Integer pageSize){
        Integer total = electricityChangeStationMapper.getElectricityChangeStationCountByMap(param);
        pageNo = EmptyUtils.isEmpty(pageNo) ? Constants.DEFAULT_PAGE_NO : pageNo;
        pageSize = EmptyUtils.isEmpty(pageSize) ? Constants.DEFAULT_PAGE_SIZE : pageSize;
        Page page = new Page(pageNo, pageSize, total);
        param.put("beginPos", page.getBeginPos());
        param.put("pageSize", page.getPageSize());
        List<ElectricityChangeStation> electricityChangeStationList = electricityChangeStationMapper.getElectricityChangeStationListByMap(param);
        page.setRows(electricityChangeStationList);
        return page;
    }

}
